<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>库视频编辑</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/img/logo.png">
    <script src="assets/js/echarts.min.js"></script>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="assets/css/app.css">
    <script src="assets/js/jquery.min.js"></script>
</head>
<body data-type="widgets">
<script src="assets/js/theme.js"></script>
<div class="am-g tpl-g">
    <!-- 头部 -->
    <header>
        <!-- logo -->
        <div class="am-fl tpl-header-logo">
            <a href="javascript:;">
                <img src="assets/img/logo.png" style="width:30px;">
            </a>
        </div>
        <!-- 右侧内容 -->
        <div class="tpl-header-fluid">
            <!-- 侧边切换 -->
            <div class="am-fl tpl-header-switch-button am-icon-list"></div>
            <!-- 其它功能-->
            <div class="am-fr tpl-header-navbar">
                <ul>
                    <!-- 欢迎语 -->
                    <li class="am-text-sm tpl-header-navbar-welcome">
                        <a href="javascript:;">欢迎你，<span>管理员</span> </a>
                    </li>
                    <!-- 新提示 -->
                    <li class="am-dropdown" data-am-dropdown id="orderNewList"></li>
                    <!-- 退出 -->
                    <li class="am-text-sm">
                        <a href="javascript:;">
                            <span class="am-icon-sign-out"></span> 退出
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </header>
    <!-- 头部 -->
    <!-- 风格切换 -->
    <div class="tpl-skiner"></div>
    <!-- 风格切换 -->
    <!-- 侧边导航栏 -->
    <div class="left-sidebar">
        <!-- 用户信息 -->
        <div class="tpl-sidebar-user-panel"></div>
        <!-- 菜单 -->
        <ul class="sidebar-nav"></ul>
    </div>
    <!-- 侧边导航栏 -->

    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <!--单个表单-->
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">
                                库视频：逐个填写
                                <span id="oper"></span>
                            </div>
                            <div class="widget-function am-fr">
                                <a href="javascript:history.go(-1);" class="am-icon-cog"> 返回</a>
                            </div>
                        </div>
                        <div class="widget-body am-fr">
                            <form class="am-form tpl-form-line-form">
                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">
                                        视频标题
                                    </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" class="tpl-form-input" id="vtitle"
                                               placeholder="请输入标题文字">
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label for="user-phone" class="am-u-sm-3 am-form-label">
                                        视频来源
                                    </label>
                                    <div class="am-u-sm-9">
                                        <select data-am-selected="{searchBox:0}" id="vtype"></select>
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">
                                        封面地址
                                    </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" id="vimg" placeholder="输入封面地址">
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">
                                        视频地址
                                    </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" id="vlink" placeholder="输入封面地址">
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">
                                        创板HTML
                                    </label>
                                    <div class="am-u-sm-9">
                                        <textarea rows="15" id="boardHtml" placeholder="请输入"></textarea>
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">
                                        创板素材数量
                                    </label>
                                    <div class="am-u-sm-9">
                                        <input type="number" id="boardNum" placeholder="输入素材个数" value="0">
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <div class="am-u-sm-9 am-u-sm-push-3">
                                        <button type="button" class="am-btn am-btn-primary
                                            tpl-btn-bg-color-success" onclick="setBack()">
                                            返回
                                        </button>
                                        <button type="button" class="am-btn am-btn-primary
                                            tpl-btn-bg-color-success" onclick="setSave()">
                                            马上提交表单
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <!--单个表单-->

                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">
                                外部视频：JSON形式
                                <span class="am-icon-plus"></span>
                            </div>
                            <div class="widget-function am-fr">
                                <a href="javascript:history.go(-1);" class="am-icon-cog"> 返回</a>
                            </div>
                        </div>
                        <div class="widget-body am-fr">
                            <form class="am-form tpl-form-border-form">
                                <div class="am-form-group">
                                    <label for="user-intro" class="am-u-sm-12 am-form-label  am-text-left">
                                        外部原生JSON
                                    </label>
                                    <div class="am-u-sm-12 am-margin-top-xs">
                                        <textarea rows="10" id="json"
                                                  placeholder="请输入"></textarea>
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <div class="am-u-sm-9 am-u-sm-push-3">
                                        <button type="button" class="am-btn am-btn-primary
                                            tpl-btn-bg-color-success" onclick="setJsonAdd()">
                                            马上提交JSON
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--自定义弹窗-->
<div id="selfPop"></div>
</body>
</html>


<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/amazeui.datatables.min.js"></script>
<script src="assets/js/dataTables.responsive.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="assets/js/myself.js"></script>
<script type="text/javascript">
    var domain = getDomain();
    var vid = getUrlParam('vid');
    (function(){
        getLeftMenus();
        getLoginUser();
        getNewOrder();
        getOne();
    })();
    //获取数据
    function getType(type){
        var vTypes = [
            "选择来源", "快手", "抖音", "刷宝", "快报",
        ];
        var i, h = '';
        for (i=0;i<vTypes.length;i++) {
            h += '<option value="'+i+'" ';
            if (i==type) {
                h += 'selected';
            }
            h += '>';
            h += vTypes[i];
            h += '</option>>';
        }
        $("#vtype").html(h);
    }
    //获取一个数据
    function getOne(){
        var formData = {
            adminAccess:adminAccess,
            vid:vid
        };
        $.ajax({
            type: 'post',
            url: domain+'/stock/one',
            data: formData,
            success: function(res){
//                console.log(res);
                if (res.code!=0) {
                    $("#oper").html('<span class="am-icon-plus"></span><input type="hidden" id="operInput" value="1"/>');
                    getType(0);
//                    getSelfPop('没有数据');
                    return
                }
                var resData = res.data;
                var vtitle = resData.videoTitle;
                var vtype = resData.videoType;
                var videoImg = resData.videoImg;
                var videoLink = resData.videoLink;
                var boardHtml = resData.boardHtml;
                var boardNum = resData.boardNum;
                $("#oper").html('<span class="am-icon-pencil"></span><input type="hidden" id="operInput" value="2"/>');
                $("#vtitle")[0].value = vtitle;
                getType(vtype);
                $("#vimg")[0].value = videoImg;
                $("#vlink")[0].value = videoLink;
                $("#boardHtml")[0].value = boardHtml;
                $("#boardNum")[0].value = boardNum;
            },
            error: function(){
//                console.log('网络错误');
                getSelfPop('网络错误');
            }
        });
    }
    //设置保存
    function setSave(){
        var oper = $("#operInput").val();
        var vtitle = $("#vtitle").val();
        var vtype = $("#vtype").val();
        var vimg = $("#vimg").val();
        var vlink = $("#vlink").val();
        var boardHtml = $("#boardHtml").val();
        var boardNum = $("#boardNum").val();
        if (!boardNum) {
            getSelfPop('素材数量'); return
        }
        var url, formData;
        if (oper==1) {
            formData = {
                adminAccess:adminAccess,
                vtitle:vtitle,
                vtype:vtype,
                vimg:vimg,
                vlink:vlink,
                boardHtml:boardHtml,
                boardNum:boardNum
            };
            url = domain+'/stock/form/add';
        } else {
            formData = {
                adminAccess:adminAccess,
                vid:vid,
                vtitle:vtitle,
                vtype:vtype,
                vimg:vimg,
                vlink:vlink,
                boardHtml:boardHtml,
                boardNum:boardNum
            };
            url = domain+'/stock/form/modify';
        }
        $.ajax({
            type: 'post',
            url: url,
            data: formData,
            success: function(res){
                console.log(res);
                if (res.code!=0) {
                    getSelfPop('操作失败');
                    return
                }
                getSelfPop('操作成功');
                return
            },
            error: function(){
//                console.log('网络错误');
                getSelfPop('网络错误');
            }
        });
    }
    //设置保存外部原生数据
    function setJsonAdd(){
        var json = $("#json").val();
        if (!json) {
            console.log('没有JSON数据')
            getSelfPop('没有JSON数据'); return
        }
//        console.log(json)
        var formData = {
            adminAccess:adminAccess,
            json:json
        };
        $.ajax({
            type: 'post',
            url: domain+'/stock/json/add',
            data: formData,
            success: function(res){
                console.log(res);
//                return
                if (res.code!=0) {
                    getSelfPop(res.msg);
                    return
                }
                getSelfPop('操作成功');
                setTimeout(function(){
                    window.location.href = domain+'stock.html?view=1&page=0';
                },1000);
            },
            error: function(){
//                console.log('网络错误');
                getSelfPop('网络错误');
            }
        });
    }
    //点击返回
    function setBack(){
        window.location.href = '/admin/stock.html?view=2&page=0';
    }
</script>